//
//  ViewController.m
//  ScrollTest
//
//  Created by Arthur on 2017/2/8.
//  Copyright © 2017年 Arthur. All rights reserved.
//

#import "ViewController.h"
#import <MapKit/MapKit.h>


typedef void(^buttonViewBlock)(void);

@interface ButtonView : UIView

@property(nonatomic,copy)buttonViewBlock clickBlock;
@property(nonatomic,weak)UIScrollView *scroller;

@end

@implementation ButtonView

//-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
//{
////    self.scroller.scrollEnabled = YES;
////    NSLog(@"asd");
//}
//
//-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
//{
//    NSLog(@"adsf");
//}

-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
//    NSLog(@"sda");
    if(self.clickBlock)
    {
        self.clickBlock();
    }
}

@end


@interface ViewController ()<UIScrollViewDelegate,UIGestureRecognizerDelegate>

@property(nonatomic,strong)UIScrollView *pageScroller;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.pageScroller = [[UIScrollView alloc]init];
    
    [self.view addSubview:self.pageScroller];
    
    self.pageScroller.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
    self.pageScroller.bounces = NO;
    self.pageScroller.backgroundColor = [UIColor lightGrayColor];
    
    UIView *contentView = [[UIView alloc]init];
    contentView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width * 2, [UIScreen mainScreen].bounds.size.height);
    
    [self.pageScroller addSubview:contentView];
    contentView.backgroundColor = [UIColor redColor];
    
    self.pageScroller.scrollEnabled = YES;
    self.pageScroller.showsHorizontalScrollIndicator = NO;
    
    self.pageScroller.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width * 2, [UIScreen mainScreen].bounds.size.height);
    
    self.pageScroller.pagingEnabled = YES;
//    self.pageScroller.scrollEnabled = NO;
    self.pageScroller.delegate = self;
    
    
    UIView *leftView = [[UIView alloc]init];
    [contentView addSubview:leftView];
    leftView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
    leftView.backgroundColor = [UIColor yellowColor];
    
    UIPanGestureRecognizer *panCtrl = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction)];
    [leftView addGestureRecognizer:panCtrl];
    panCtrl.delegate = self;
    
    ButtonView *jumpButton = [[ButtonView alloc]init];
    [contentView addSubview:jumpButton];
    jumpButton.frame = CGRectMake([UIScreen mainScreen].bounds.size.width - 70, [UIScreen mainScreen].bounds.size.height / 2 - 70 / 2, 70, 70);
    jumpButton.backgroundColor = [UIColor brownColor];
    jumpButton.scroller = self.pageScroller;
    jumpButton.clickBlock = ^{
        [self.pageScroller setContentOffset:CGPointMake([UIScreen mainScreen].bounds.size.width, 0) animated:YES];
    };
    
    UIView *rightView = [[UIView alloc]init];
    [contentView addSubview:rightView];
    rightView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
    rightView.backgroundColor = [UIColor blueColor];
    
    MKMapView *miniScroller = [[MKMapView alloc]init];
    [rightView addSubview:miniScroller];
    miniScroller.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
//    miniScroller.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width * 2, [UIScreen mainScreen].bounds.size.height / 2);
    UIView *miniContentView = [[UIView alloc]init];
//    [miniScroller addSubview:miniContentView];
    miniContentView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width * 2, [UIScreen mainScreen].bounds.size.height);
    miniContentView.backgroundColor = [UIColor purpleColor];
    
    ButtonView *ctrlButton = [[ButtonView alloc]init];
    [rightView addSubview:ctrlButton];
    ctrlButton.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height / 2 - 70 / 2, 70, 70);
    ctrlButton.clickBlock = ^{
        [self.pageScroller setContentOffset:CGPointMake(0, 0) animated:YES];
    };
    
    ctrlButton.backgroundColor = [UIColor whiteColor];
}

-(void)panAction
{
//    NSLog(@"hello");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
